<template>
  <view class="QrPopup" v-if="flag">
    <Toast ref="Toast" />
    <view :class="'container ' + toastAnimate">
      <view class="close CloseBtn" @click="close"></view>
      <view class="title">
        {{ title }}
      </view>
      <view class="qr" :style="'background-image:url(' + qr + ')'"></view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      flag: false,
      toastAnimate: "",
      title: "",
      qr: "",
    };
  },
  methods: {
    close: function () {
      this.toastAnimate = "toastAnimateOut";
      setTimeout(() => {
        this.flag = false;
      }, 250);
    },
    show: function (json) {
      this.flag = true;
      this.toastAnimate = "toastAnimate";
      this.title = json.title;
      this.qr = json.data;
    },
  },
};
</script>
<style scoped lang="scss">
.QrPopup {
  font-size: 15px;
  z-index: 99999999999;
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.5);

  & > .container {
    position: absolute;
    top: 50%;
    left: 50%;
    height: auto;
    width: 70%;
    border-radius: 20rpx;
    transform: translate(-50%, -50%) scale(0.5);
    background: #fff;
    opacity: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 70rpx 0;
    box-sizing: border-box;
    & > .close {
      position: absolute;
      top: 20rpx;
      right: 20rpx;
      height: 50rpx;
      width: 50rpx;
      background: rgba(0, 0, 0, 0.5);
      z-index: 100000;
    }
    .title {
      position: relative;
      font-size: 48rpx;
      font-weight: bold;
      padding-bottom: 30rpx;
    }
    .qr {
      position: relative;
      width: 300rpx;
      height: 300rpx;
      background-repeat: no-repeat;
      background-origin: center center;
      background-size: 100% auto;
    }
  }

  .toastAnimateOut {
    animation: toastAnimateOut 0.3s ease-out forwards;
  }
  .toastAnimate {
    animation: toastAnimate 0.3s ease-out forwards;
  }
  @keyframes toastAnimate {
    0% {
      transform: translate(-50%, -50%) scale(0.7);
      opacity: 0;
    }
    50% {
      transform: translate(-50%, -50%) scale(1.05);
      opacity: 1;
    }
    100% {
      transform: translate(-50%, -50%) scale(1);
      opacity: 1;
    }
  }
  @keyframes toastAnimateOut {
    0% {
      transform: translate(-50%, -50%) scale(1);
      opacity: 1;
    }
    50% {
      transform: translate(-50%, -50%) scale(0.7);
      opacity: 0;
    }
  }
}
</style>
